<template>
  <div class="DynamicTable">
    <el-table
      :data="tableData"
      :key="itemKey"
      border
      style="width: 100%"
      :header-row-style="{ height: '40px' }"
      :header-cell-style="{
        fontSize: '14px',
        fontWeight: 600,
        textShadow: '0px 2px 4px rgba(59, 81, 95, 0.24)'
      }"
      :row-style="rowStyle"
      :cell-style="cellStyle"
      height="100%"
    >
      <el-table-column
        v-for="(column, index) in columnConfigs"
        :key="index + 'dynamic'"
        :type="column.type"
        :prop="column.prop"
        :label="column.label"
        :width="column.width"
        :fixed="column.fixed"
        :align="column.align"
        :show-overflow-tooltip="true"
      >
      <template v-if="column.headerRender && typeof column.headerRender === 'function'" #header>
          <component :is="column.headerRender(h,column)"></component>
        </template>
        <template #default="{row,$index}">
          <slot v-if="column.cellSlot" :name="column.cellSlot" :row="row" :index="$index+1"></slot>
          <div v-else-if="column.render && typeof column.render === 'function'">
            <component :is="column.render(h,row,$index,row)"></component>
          </div>
          <span v-else>{{ column.type==='index'?$index+1:row[column.prop] }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, watch, computed } from "vue";

// const tableData = ref([]);
const props = defineProps(["tableHeaderConfigs","tableData"]);
const columnConfigs = computed(()=>{
  let newColumnConfigs = props.tableHeaderConfigs.filter(x=>{
    if(!x.isHidden) return x;
  })
  return newColumnConfigs;
})
// watch(()=>props.tableHeaderConfigs,(newValue,oldValue)=>{
//   debugger
// },{deep:true})

// function rowStyle({ row, rowIndex }) {
//   return { height :"35px"}
// }
// function cellStyle({ row, column, rowIndex, columnIndex }) {
//   if (rowIndex % 2 == 0 && columnIndex % 2 == 0) {
//     return { background: "rgb(245, 248, 251)" };
//   }
// }
function rowStyle({ row, rowIndex }) {
  if (rowIndex % 2 == 0) {
    return { height: "35px", background: "#F5F8FB" };
  } else {
    return { height: "35px" };
  }
}
function cellStyle({ row, column, rowIndex, columnIndex }) {
  if (rowIndex % 2 == 0 && columnIndex % 2 == 0) {
    return { background: "rgb(245, 248, 251)" };
  }
}
</script>

<style lang="less" scoped>
.DynamicTable {
  height: 100%;
}
</style>
